/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025/2/16
 */
public class leetcode_121 {
    public static void main(String[] args) {
        int[] ints = {7, 1, 5, 3, 6, 4};
        System.out.println(maxProfit(ints));
    }

    public static int maxProfit(int[] prices) {
        int min = Integer.MAX_VALUE;
        int profit = 0;
        int maxProfit = 0;
        for (int price : prices) {
            if(price<min)min = price;
            else {
                profit = price-min;
                maxProfit = Math.max(profit,maxProfit);
            }
        }
        return profit;
    }
}
